using NUnit.Framework;
using PuvBuilder;
using System;
using System.Collections.Generic;

namespace PuvBuilderTest
{
    public class Tests
    {
        PuvBuilder.Builder Builder;

        [SetUp]
        public void Setup()
        {
            Builder = new PuvBuilder.Builder(new PuvBuilder.Options()
            {
                DefaultSqlServerConnectionString = "Server=192.168.31.13;database=iSchoolArticle;user id=iSchool;password=SxbLucas$0769;MultipleActiveResultSets=true;"
            });
        }

        [Test]
        public void Test1()
        {
            Builder.Run(GetTestTask(), GetTestFilter());
            Assert.Pass();
        }

        private IEnumerable<PuvTask> GetTestTask()
        {
            return new List<PuvTask>()
            {
                new PuvTask(){
                    Name = "test1",
                    ConnectionStr = "default",
                    LastExecuteTime = DateTime.Now.AddDays(-10),
                    Sql = ""
                }
            };
        }

        private IEnumerable<PuvFilter> GetTestFilter()
        {
            return new List<PuvFilter>()
            {
                //https://m3.sxkid.com/school_detail_wechat/eid=092D223A-5D02-48FF-AE04-FD1C9683EB5D
                //https://m3.sxkid.com/school_detail_wechat/data/eid=092D223A-5D02-48FF-AE04-FD1C9683EB5D_type=1
                new PuvFilter(){ Name = "Task1", UrlRegex = "^https://m.?\\.sxkid.com/school_detail_wechat/", KeyCode = "WeChatSchool"},
                
                //https://m.sxkid.com/school/wechat/vnzfa
                //https://m.sxkid.com/school/wechat/detail/vnzfa_type=1
                new PuvFilter(){ Name = "Task1", UrlRegex = "^https://m.?\\.sxkid.com/school/wechat/", KeyCode = "WeChatSchool"},
            };
        }

        public IEnumerable<PuvItem> GetTestData()
        {
            var random = new Random();
            for (int i = 0; i < 10; i++)
            {
                var t = i % 3;

                var url = "https://m.sxkid.com/school_detail_wechat/" + i;
                if (t == 0)
                {
                    url = "https://m.sxkid.com/school/wechat/" + i;
                }
                else if (t == 1)
                {
                    url = "https://m.sxkid.com/test" + i;
                }
                yield return new PuvItem()
                {
                    Url = url,
                    KeyCode = null,
                    ViewDate = DateTime.Now.AddDays(-random.Next(i)),
                    Pv = i + random.Next(i),
                    Uv = i
                };
            }
        }
    }
}